package com.yx.cloud.activity;

import android.app.Dialog;
import android.view.View;
import android.widget.TextView;

import com.aaa.async.DoneCallback;
import com.aaa.async.FailCallback;
import com.iot.sweeper.AppContext;
import com.iot.sweeper.param.ResetComsuptionParam;
import com.yx.cloud.R;
import com.yx.cloud.base.BaseActivity;
import com.yx.cloud.databinding.ConsumablemaintenanceinformationActivtyBinding;
import com.yx.cloud.utils.Intent_utils;
import com.yx.cloud.utils.LoadProgressDialog;
import com.yx.cloud.utils.RomUtils;

/**
 * 耗材与保养信息显示界面(滤网 边刷 主刷 传感器)
 */
public class ConsumableMaintenanceInformationActivty extends BaseActivity implements View.OnClickListener {
    private String consunables;
    private Dialog dialog;
    private String surplusTime;
    private String workTime;
    private LoadProgressDialog loadProgressDialog;
    private float base_sideBrush_percentage = 720000f;
    private float base_mianBrush_percentage = 1080000f;
    private float base_filter_percentage = 540000f;
    private float base_mop_percentage = 540000f;
    private ConsumablemaintenanceinformationActivtyBinding binding;

    @Override
    public void onCreate() {
        binding = ConsumablemaintenanceinformationActivtyBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        consunables = getIntent().getStringExtra("consunables");
        surplusTime = getIntent().getStringExtra("surplusTime");
        workTime = getIntent().getStringExtra("workTime");
        initData();

    }

    private void initData() {
        if (loadProgressDialog == null) {
            loadProgressDialog = new LoadProgressDialog(this);
        }

        if ("Strainer".equals(consunables)) {
            //滤网
            binding.ivConsumablesLegend.setImageResource(R.mipmap.strainer_pic);
            binding.tvConsumablesTitle.setText(getString(R.string.U_DustFilter));
            binding.tvConsumablesTime.setText(workTime);
            binding.tvConsumablesResidue.setText(surplusTime + "");
            binding.btnRestoration.setText(getString(R.string.U_Reset));
            binding.tvConsumablesExplain.setText(getString(R.string.MO_DustFilter_Tip));

        } else if ("Water".equals(consunables)) {
            //水箱滤网
            binding.ivConsumablesLegend.setImageResource(R.mipmap.strainer_pic);
            binding.tvConsumablesTitle.setText(getString(R.string.U_MopFilter));
            binding.tvConsumablesTime.setText(workTime);
            binding.tvConsumablesResidue.setText(surplusTime + "");
            binding.btnRestoration.setText(getString(R.string.U_Reset));
            binding.tvConsumablesExplain.setText(getString(R.string.MO_DustFilter_Tip));
        } else if ("Sidebrush".equals(consunables)) {
            //边刷
            binding.ivConsumablesLegend.setImageResource(R.mipmap.sidebrush_pic);
            binding.tvConsumablesTitle.setText(getString(R.string.U_SideBrush));
            binding.tvConsumablesTime.setText(workTime);
            binding.tvConsumablesResidue.setText(surplusTime + "");
            binding.btnRestoration.setText(getString(R.string.U_Reset));
            binding.tvConsumablesExplain.setText(getString(R.string.MO_SideBrush_Tip));

        } else if ("Brush".equals(consunables)) {
            //主刷
            binding.ivConsumablesLegend.setImageResource(R.mipmap.brush_pic);
            binding.tvConsumablesTitle.setText(getString(R.string.U_MainBrush));
            binding.tvConsumablesTime.setText(workTime);
            binding.tvConsumablesResidue.setText(surplusTime + "");
            binding.btnRestoration.setText(getString(R.string.U_Reset));
            binding.tvConsumablesExplain.setText(getString(R.string.MO_MainBrush_Tip));

        } else if ("Sensor".equals(consunables)) {
            //传感器
            binding.ivConsumablesLegend.setImageResource(R.mipmap.sensor_pic);
            binding.tvConsumablesTitle.setText(getString(R.string.Sensor));
            binding.tvConsumablesTime.setText(workTime);
            binding.tvConsumablesResidue.setText(surplusTime + "");
            binding.btnRestoration.setText(getString(R.string.U_Reset));
            binding.tvConsumablesExplain.setText(getString(R.string.Sensor_particulars));
        } else if ("bag".equals(consunables)) {
            //集尘袋
            binding.ivConsumablesLegend.setImageResource(R.mipmap.bag_pic);
            binding.tvPerCent.setVisibility(View.GONE);//百分号
//            mSurplus.setText("状态");
            binding.tvConsumablesTitle.setText(getString(R.string.bag));
            binding.btnRestoration.setText(getString(R.string.U_Reset));
            binding.tvConsumablesExplain.setText(getString(R.string.bag_particulars));
        } else if ("mop".equals(consunables)) {
            //拖布
            binding.ivConsumablesLegend.setImageResource(R.mipmap.mop_pic);
            binding.tvConsumablesTitle.setText(getString(R.string.U_Mop));
            binding.tvConsumablesTime.setText(workTime);
            binding.tvConsumablesResidue.setText(surplusTime + "");
            binding.btnRestoration.setText(getString(R.string.U_Reset));
            binding.tvConsumablesExplain.setText(getString(R.string.MO_Mop_Tip));
        }

        binding.ivConsumablesMaintenanceReturn.setOnClickListener(this);
        binding.btnRestoration.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        if (RomUtils.isFastClick()) {
            return;
        }
        switch (v.getId()) {
            case R.id.iv_consumablesMaintenanceReturn:
                Intent_utils.backIntent(this);
                break;
            case R.id.btn_restoration:
                ResetComsuptionParam param = new ResetComsuptionParam();

                if ("Strainer".equals(consunables)) {
                    //滤网
                    param.setReset("resetFilter");
                    restorationDialogTitle = getString(R.string.MO_ResetDustFilter_Tip);
                } else if ("Water".equals(consunables)) {
                    //水箱滤网
                    param.setReset("waterTankFilter");
                    restorationDialogTitle = getString(R.string.MO_ResetMopFilter_Tip);
                } else if ("Sidebrush".equals(consunables)) {
                    //边刷
                    param.setReset("resetSidebrush");
                    restorationDialogTitle = getString(R.string.MO_ResetSideBrush_Tip);
                } else if ("Brush".equals(consunables)) {
                    //主刷
                    param.setReset("resetMainbrush");
                    restorationDialogTitle = getString(R.string.MO_ResetMainBrush_Tip);
                } else if ("Sensor".equals(consunables)) {
                    param.setReset("resetSensor");
                    //传感器
                    mContent = "";
                } else if ("mop".equals(consunables)) {
                    param.setReset("mop");
                    //拖布
                    restorationDialogTitle = getString(R.string.MO_ResetMop_Tip);
                }
                setRestorationDialog(restorationDialogTitle, param);
                break;
        }
    }

    private String mContent, restorationDialogTitle;

    private void setRestorationDialog(String dialogTitle, Object obj) {
        dialog = new Dialog(ConsumableMaintenanceInformationActivty.this);
        dialog.setContentView(R.layout.content_centered_dialog);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.setCanceledOnTouchOutside(false);
        TextView mBtnRestorationConfirm = dialog.findViewById(R.id.btn_centered_Confirm);
        TextView mBtnRestorationCancel = dialog.findViewById(R.id.btn_centered_Cancel);
        TextView mTvDialogTitle = dialog.findViewById(R.id.tv_centered_dialogTitle);
        mTvDialogTitle.setText(dialogTitle);
        mBtnRestorationConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                //重置(耗材复位)
                AppContext.getProductService().resetComsuptionInfo((ResetComsuptionParam) obj);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                finish();
            }
        });
        mBtnRestorationCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }


}
